<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>第三题</title>
    <link rel="stylesheet" href="./index.css">
</head>

<body>
    <table>
        <thead>
            <tr>
                <th>名次</th>
                <th>姓名</th>
                <th>年纪</th>
                <th>性别</th>
                <th>销售额</th>
                <th>业绩状态</th>
            </tr>
            <!-- <tr>
                <td>0</td>
                <td>小明</td>
                <td>18</td>
                <td>男</td>
                <td>30</td>
                <td>未及格</td>
            </tr> -->
        </thead>
        <tbody>

        </tbody>
    </table>
    <script>

        let sales = [
            { name: '小明', age: 18, gender: '男', money: 30, status: 0 },
            { name: '小红', age: 26, gender: '女', money: 99, status: 3 },
            { name: '小刚', age: 19, gender: '男', money: 88, status: 2 },
            { name: '小丽', age: 20, gender: '女', money: 67, status: 1 },
            { name: '晓强', age: 23, gender: '女', money: 77, status: 1 },
            { name: '小张', age: 25, gender: '女', money: 80, status: 2 },
        ]
        const tbody = document.querySelector('tbody')
        sales.sort((a, b) => b.money - a.money)
        // /console.log(sales)
        let arr = sales.map(function (item) {
            item.money = item.money + 'W'
            return item
        })
        // /console.log(arr)
        let newsales = {
            0: '未及格',
            1: '及格',
            2: '良好',
            3: '优秀',
        }
        for (let i = 0; i < sales.length; i++) {
            sales[i].status = newsales[sales[i].status]
            // document.write(`${sales[i].name}${newsales[sales[i].status]}`)
        }
        console.log(sales)

        function getsales() {
            for (let i = 0; i < sales.length; i++) {
                const tr = document.createElement('tr')
                console.log(tr)
                tr.innerHTML = `
                    <td>${i + 1}</td>
                    <td>${sales[i].name}</td>
                    <td>${sales[i].age}</td>
                    <td>${sales[i].gender}</td>
                    <td>${sales[i].money}</td>
                    <td>${sales[i].status}</td>`
                tbody.appendChild(tr)
            }
        }
        getsales()
    </script>
</body>

</html>